package com.liuhan.house.service.impl;

import com.liuhan.house.pojo.House;
import com.liuhan.house.service.HouseService;
import com.liuhan.house.service.RecommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class RecommandServiceImpl implements RecommandService {
    @Autowired
    private HouseService houseService;
    private static final String HOT_HOUSE_KEY = "hot_house";

    public void increase(Integer id) {
        Jedis jedis = new Jedis("127.0.0.1");
        jedis.zincrby(HOT_HOUSE_KEY, 1, id + "");
        jedis.zremrangeByRank(HOT_HOUSE_KEY, 10, -1);
        jedis.close();
    }

    public List<Integer> getHost() {
        Jedis jedis = new Jedis("127.0.0.1");
        Set<String> idSet = jedis.zrange(HOT_HOUSE_KEY, 10, -1);
        jedis.close();
        List<Integer> ids = idSet.stream().map(Integer::parseInt).collect(Collectors.toList());
        return ids;
    }

    @Override
    public List<House> getHotHouse(Integer size) {
        House query = new House();
//        query.setHouseId(getHost());

//        return houseService;
        return null;
    }
}
